<?php 
	include_once 'dataservice.php';
	include_once 'thuvienham.php';

	class caidathethong_db 
	{
		public function Them($ThoiGianDangXuat, $EThayDoiCapQuyen, $EKhiDatLaiMatKhau, $EKhiXoaNguoiDung, $EKhiCapNhatNguoiDung, $EKhiThemNguoiDung)
		{
			$sql = "INSERT INTO `tbl_caidathethong`(`ThoiGianDangXuat`, `EThayDoiCapQuyen`, `EKhiDatLaiMatKhau`, `EKhiXoaNguoiDung`, `EKhiCapNhatNguoiDung`, `EKhiThemNguoiDung`)
					VALUES ('$ThoiGianDangXuat', '$EThayDoiCapQuyen', '$EKhiDatLaiMatKhau', '$EKhiXoaNguoiDung', '$EKhiCapNhatNguoiDung', '$EKhiThemNguoiDung')";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function Xoa($ThoiGianDangXuat)
		{
			$sql = "DELETE FROM `tbl_caidathethong` WHERE `ThoiGianDangXuat` = '$ThoiGianDangXuat'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function CapNhat($ThoiGianDangXuat, $EThayDoiCapQuyen, $EKhiDatLaiMatKhau, $EKhiXoaNguoiDung, $EKhiCapNhatNguoiDung, $EKhiThemNguoiDung)
		{
			$sql = "UPDATE `tbl_caidathethong`
					SET `EThayDoiCapQuyen` = '$EThayDoiCapQuyen', `EKhiDatLaiMatKhau` = '$EKhiDatLaiMatKhau', `EKhiXoaNguoiDung` = '$EKhiXoaNguoiDung', `EKhiCapNhatNguoiDung` = '$EKhiCapNhatNguoiDung', `EKhiThemNguoiDung` = '$EKhiThemNguoiDung'
					WHERE `ThoiGianDangXuat` = '$ThoiGianDangXuat'";

			$service = new dataservice();
			return $service->ExecuteNonQuery($sql);
		}

		public function LayDanhSach($ThoiGianDangXuat, $EThayDoiCapQuyen, $EKhiDatLaiMatKhau, $EKhiXoaNguoiDung, $EKhiCapNhatNguoiDung, $EKhiThemNguoiDung)
		{
			$sql = "SELECT * FROM `tbl_caidathethong` WHERE 1  ";
			if($ThoiGianDangXuat != -1)
				$sql .= " AND `ThoiGianDangXuat` = '$ThoiGianDangXuat' ";

			if($EThayDoiCapQuyen != -1)
				$sql .= " AND `EThayDoiCapQuyen` = '$EThayDoiCapQuyen' ";

			if($EKhiDatLaiMatKhau != -1)
				$sql .= " AND `EKhiDatLaiMatKhau` = '$EKhiDatLaiMatKhau' ";

			if($EKhiXoaNguoiDung != -1)
				$sql .= " AND `EKhiXoaNguoiDung` = '$EKhiXoaNguoiDung' ";

			if($EKhiCapNhatNguoiDung != -1)
				$sql .= " AND `EKhiCapNhatNguoiDung` = '$EKhiCapNhatNguoiDung' ";

			if($EKhiThemNguoiDung != -1)
				$sql .= " AND `EKhiThemNguoiDung` = '$EKhiThemNguoiDung' ";

			$service = new dataservice();
			return $service->ExecuteQuery($sql);
		}

	}

